﻿using System;

class QuadraticEquation
{
    static void Main()
    {
        //Exercise 6.
        //Write a program that enters the coefficients a, b and c of a quadratic equation
		//a*x2 + b*x + c = 0
		//and calculates and prints its real roots. Note that quadratic equations may have 0, 1 or 2 real roots.

        Console.Write("Enter coefficient a:  ");
        double a = double.Parse(Console.ReadLine());
        Console.Write("Enter coefficient b:  ");
        double b = double.Parse(Console.ReadLine());
        Console.Write("Enter coefficient c:  ");
        double c = double.Parse(Console.ReadLine());
        double discriminant = (b * b) - (4 * a * c);
        double result;
        double resultTwo;
        Console.WriteLine();

        if (discriminant == 0)
        {
            result = (-b) / (2 * a);
            Console.WriteLine("The equation has one root:  {0:0.00}", result);
        }
        else
        {
            if (discriminant > 0)
            {
                result = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
                resultTwo = ((-b) - Math.Sqrt(discriminant)) / (2 * a);
                Console.WriteLine("The equation has two roots:  {0:0.00}  and  {1:0.00} ", result, resultTwo);
            }
            else
            {
                Console.WriteLine("The equation does not have a real root.");
            }
        }
        Console.WriteLine();
    }
}

